module Loan where

import Date
import IdObject

type LoanInfo = (Int, -- id klienta
		Int, -- id filmu
		Date, -- data wypozyczenie
		Date, -- deklarowana data zwrotu
		Date) -- rzeczywista data zwrotu				

data Loan =
	Loan Int LoanInfo
		deriving (Show, Read)

instance IdObjectClass Loan where
        getId (Loan i l) = i
        getParam paramId loan   | paramId == 1  = show (getClientId loan)
                                | paramId == 2  = show (getFilmId loan)
                                | paramId == 3  = show (getDateLoaned loan)
                                | paramId == 4  = show (getDateObliged loan)                                
                                | otherwise     = show (getDateReturned loan)
        getParamNum loan = 5
        toList loan = (show (getId loan)) : (show (getClientId loan)) : (show(getFilmId loan)) 
                : (show (getDateLoaned loan)) : (show (getDateObliged loan))
                : (show (getDateReturned loan)) : []

instance Eq Loan where
	(Loan id1 _) == (Loan id2 _) = (id1 == id2)

-- getters
getClientId :: Loan -> Int
getClientId (Loan i (idClient, idFilm, dateLoaned, dateObliged, dateReturned)) = idClient

getFilmId :: Loan -> Int
getFilmId (Loan i (idClient, idFilm, dateLoaned, dateObliged, dateReturned)) = idFilm

getDateLoaned :: Loan -> Date
getDateLoaned (Loan i (idClient, idFilm, dateLoaned, dateObliged, dateReturned)) = dateLoaned

getDateObliged :: Loan -> Date
getDateObliged (Loan i (idClient, idFilm, dateLoaned, dateObliged, dateReturned)) = dateObliged

getDateReturned :: Loan -> Date
getDateReturned (Loan i (idClient, idFilm, dateLoaned, dateObliged, dateReturned)) = dateReturned

-- setters
setDateLoaned :: Loan -> Date -> Loan
setDateLoaned (Loan i (c, f, datel, dateo, dater)) newVal = Loan i (c, f, newVal, dateo, dater)

setDateObliged :: Loan -> Date -> Loan
setDateObliged (Loan i (c, f, datel, dateo, dater)) newVal = Loan i (c, f, datel, newVal, dater)

setDateReturned :: Loan -> Date -> Loan
setDateReturned (Loan i (c, f, datel, dateo, dater)) newVal = (Loan i (c, f, datel, dateo, newVal))

